<?php

/**
 * Mediad co,ltd
 *
 * @category   Mediad2
 * @package    Mediad2_Service
 * @subpackage Util
 * @copyright  Copyright (c) 2012 Mediad co,ltd. (http://www.Mediad.cn)
 * @license    New BSD License
 * @version    $Id: Validate.php 1 2012-05-12 10:42:00Z vincent@Mediad.cn
 */

require_once 'Zend/Validate.php';

/**
 * @category   Mediad
 * @package    Service
 * @subpackage Util
 */
class Mediad2_Service_Util_Validate extends Zend_Validate{
			
	private $value;
	private $intService;
	private $emailService;
	
	public function __construct($type_validate=null)
    {   
    	$this->intService = new Zend_Validate_Int();
    	$this->emailService = new Zend_Validate_EmailAddress();
    }  

    
    /**
     * @param int $key 验证数字
     * @param int $min 最小长度(可填)
     * @param int $max 最大长度(可填)
     * @return boolean
     */
    public function int_validate($key,$min=null,$max=null){
    	$result = false;
    	
    	if(empty($key)){
    		return $result;
    	}
    	
    	$keyLength =strlen($key);
    	
    	if(empty($min)&&empty($max)) {    		
    		$result = $this->intService->isValid($key);
    	}
    	
    	if(!empty($min)&&!empty($max)) {    		
    		if($keyLength>=$min||$keyLength<=$max) {    			
    			$result = $this->intService->isValid($key);
    		}
    	}
    	
    	return $result;
    }	
    
    
    /**
     * @param 电子邮箱 $key
     * @return boolean
     */
    public function email_validate($key){
    	$result = false;
    
    	if(empty($key)){
    		return $result;
    	}
    
    	$result = $this->emailService->isValid($key);
    	return $result;
    }
}